var myGrid;
$(function(){
	myGrid = $("#list").jqGrid({
			url : "admin/form/form-manager!datalist",
			datatype : "json",
			mtype : 'GET',
			colNames : [ '名称','预览','编辑','删除' ],
			colModel : [ {
				name : 'name',
				index : 'name',
				width : 200
				
			}, {
				name : 'id',
				index : 'id',
				width : 30,
				formatter : viewFormatter
			}, {
				name : 'id',
				index : 'id',
				width : 30,
				formatter : editFormatter
			}, {
				name : 'id',
				index : 'id',
				width : 30,
				formatter : deleteFormatter
			}],
			pager : '#pager',
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			sortname : 'name',
			sortorder : 'asc',
			viewrecords : true,
			caption : "HTML模板列表",
			width : '750',
			height : '300',
			jsonReader : {
				repeatitems : false,
				id : "0"
			}
		});	
	
	
	myGrid.jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	});
	myGrid.jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			doAjaxLoad("admin/form/start");
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加新模板",
		id : "newGroup"
	});
	

});
function viewFormatter(cv,opt,row){
	var fid = row['id'];
	var url="admin/form/form-manager!preview?bean.id="+fid;
	var link=$("<a href='javascript:viewform(\""+url+"\");'>预览</a>");
	return $("<span></span>").append(link).html();
}
function editFormatter(cv,opt,row){
	var fid = row['id'];
	var url="admin/form/form-manager!get?bean.id="+fid;
	var link=$("<a href='javascript:editform(\""+url+"\");'>编辑</a>");
	return $("<span></span>").append(link).html();
}
function deleteFormatter(cv,opt,row){
	var id = row['id'];
	var link=$("<a href='javascript:removeForm(\""+id+"\");'>删除</a>");
	return $("<span></span>").append(link).html();
}
function removeForm(id){
	if(!confirm("要删除此模板吗??"))return false;
	$.ajax({
		"url":"admin/form/form-manager!remove",
		"data":"bean.id="+id,
		"success":function(){
			createNotify("删除完毕!");
			myGrid.trigger("reloadGrid");
		}
	});	
}
function editform(url){
	window.open(url,"myformwindow");
}
function viewform(url){	
	window.open(url,"myformwindow");
	return;
}
